﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;
using System.Windows.Forms;

namespace Classes
{
    public class MySQLDB
    {
       // private string MySQLConnString = "Server=localhost;Database=saviostrass2;Uid=root;Pwd=novalis13579";
        private DataSet ds;
        private MySqlCommand cmd;
        private DataTable dataTable;

        public MySqlConnection Conn(string MySQLConnString)
        {
            MySqlConnection conn = new MySqlConnection(MySQLConnString);
            return conn;
        }

        // public


        public DataTable pesquisar(MySqlConnection SqlCon,string pSQL)
        {

           // MySqlConnection SqlCon = Conn();
            SqlCon.Open();

            ds = new DataSet();

            try
            {

                if (SqlCon.State == ConnectionState.Closed)
                    SqlCon.Open();
                cmd = new MySqlCommand(pSQL, SqlCon);
                ds = new DataSet();

                /* Executa a query */
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                dataTable = new DataTable();

                /* faz o retorno dentro do dataset */
                da.Fill(dataTable);
                da.Fill(ds);

                da.Dispose();
                return dataTable;
            }
            catch (Exception e)
            {
                MessageBox.Show("Erro ao pesquisar dados.\r\nErro-> " + e.Message, "Erro",
                                 MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return null;
            }
        }


    }
}
